/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package processamento;

import java.awt.image.Raster;
import java.awt.image.WritableRaster;
import javax.media.jai.PlanarImage;
import javax.media.jai.TiledImage;

/**
 *
 * @author Igor
 */
public class OperadorSegmentaPele2 {
    
    public static PlanarImage segmentaPele(PlanarImage pi) {
    int width = pi.getWidth();
        int height = pi.getHeight();

        Raster inputRaster = pi.getData();
        WritableRaster outputRaster = inputRaster.createCompatibleWritableRaster();
            int[] pixel = new int[3];

            for(int i =0; i < width; i++)
            {
                for (int h =0;h<height;h++) {
                    pixel = inputRaster.getPixel(i, h, pixel);
                    if (pixel[0]>95 && pixel[1]>40 && pixel[2]>20 && Math.abs(pixel[0]-pixel[1])>=15 && pixel[0]>pixel[1] && pixel[0]>pixel[2]) {
                        pixel[0]=255;pixel[1]=255;pixel[2]=255;
                    } else {
                        pixel[0]=0;pixel[1]=0;pixel[2]=0;
                    }
                        outputRaster.setPixel(i, h,pixel);
                }
            }

            TiledImage ti = new TiledImage(pi, width, height);
            ti.setData(outputRaster);
            return ti;
    }

}
